﻿// FIV Fast Image viewer
// http://code.google.com/p/fiv/
// 
// Copyright 2013, Ken Rentz.
//
// This is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation; either version 2.1 of
// the License, or (at your option) any later version.
//
// This software is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this software; if not, write to the Free
// Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
// 02110-1301 USA, or see the FSF site: http://www.fsf.org.
// 
 
using System.ComponentModel;
using FIV.Properties;

namespace FIV
{
	public class Options : INotifyPropertyChanged
	{
		public event PropertyChangedEventHandler PropertyChanged;

		private static readonly Options _Instance = new Options();

		public static Options Instance
		{
			get
			{
				return _Instance;
			}
		}

		private Options()
		{
			LoadFromSettings();
		}

		private bool _FitToWindow;
		public bool FitToWindow
		{
			get { return _FitToWindow; }
			set
			{
				if (_FitToWindow != value)
				{
					_FitToWindow = value;
					OnPropertyChanged("FitToWindow");
				}
			}
		}

		private bool _MaintainAspectRatio;
		public bool MaintainAspectRatio
		{
			get { return _MaintainAspectRatio; }
			set
			{
				if (_MaintainAspectRatio != value)
				{
					_MaintainAspectRatio = value;
					OnPropertyChanged("MaintainAspectRatio");
				}
			}
		}

		public void Save()
		{
			SaveToSettings();
			Settings.Default.Save();
		}

		public void Cancel()
		{
			Settings.Default.Reload();
			LoadFromSettings();
		}

		public void Reset()
		{
			Settings.Default.Reset();
			LoadFromSettings();
		}

		private void SaveToSettings()
		{
			Settings.Default.FitToWindow = FitToWindow;
			Settings.Default.MaintainAspectRatio = MaintainAspectRatio;
		}

		private void LoadFromSettings()
		{
			FitToWindow = Settings.Default.FitToWindow;
			MaintainAspectRatio = Settings.Default.MaintainAspectRatio;
		}

		public Options Clone()
		{
			Options other = (Options)MemberwiseClone();
			return other;
		}

		protected void OnPropertyChanged(string name)
		{
			PropertyChangedEventHandler handler = PropertyChanged;
			if (handler != null)
			{
				handler(this, new PropertyChangedEventArgs(name));
			}
		}
	}
}